var gulp=require("gulp");
var webserver=require("gulp-webserver"),
    sass=require('gulp-ruby-sass'),
    livereload=require("gulp-livereload"),
    imagemin=require("gulp-imagemin"),
    pngquant=require("imagemin-pngquant");

gulp.task("webserver",function(){
    gulp.src("dist")
        .pipe(webserver({
            livereload:true,
            open:true
        }))
});


gulp.task("sass",function(){
    return sass('src/sass/*.scss',{style:"compact"})
        .on("error",function(err){
            console.log("编译错误，err.message")
        })
        .pipe(gulp.dest('dist/css'));
});
gulp.task("html",function(){
    return gulp.src("src/**/*.html")
        .pipe(gulp.dest("dist"))
});

gulp.task("css",function () {
    return gulp.src("src/sass/**/*.css")
        .pipe(gulp.dest("dist/css"))
})
gulp.task('watch', function () {
    gulp.watch('src/**/*.html',["html"]);
    gulp.watch('src/sass/*.scss',["sass"]);
});

gulp.task("jsmove",function () {
    return gulp.src("src/js/**/*.js")
        .pipe(gulp.dest("dist/js"))
});

gulp.task("watch",function () {
    gulp.watch('src/**/*.html',["html"]);
    gulp.watch('src/sass/*.scss',["sass"]);
    gulp.watch("src/js/**/*.js",["jsmove"]);
    gulp.watch("src/sass/**/*.css",["css"])
})

gulp.task("default",["watch","webserver","sass","html","jsmove","css"]);
